<?php
/*
	佣金管理
*/
defined('BY_JYA') or exit('error');
$tabs=array(
	array('op'=>'list','title'=>'佣金列表'),
	
);
$_RQ['op']=$_RQ['op']?:'list';
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$total='';
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('commission',$parameter,$total);
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'佣金管理'),
		),
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'type','title'=>'佣金类型','type'=>'radio','options'=>'types'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'statuss'),
			array('name'=>'createtime','title'=>'产生时间','type'=>'time'),
			array('name'=>'balancesn','title'=>'结算单号','type'=>'string'),
		)),
		'search'=>array(
			array('type'=>'choose','name'=>'mid','title'=>'所属代理商','action'=>'member.get_member','plugin'=>'core'),
			array('type'=>'radio','name'=>'status','title'=>'佣金状态','options'=>'statuss'),
		),
	);
	$return['htmls']=$htmls;
	$return['types']=array(
		'1'=>'省级代理分红',
		'2'=>'市级代理分红',
		'3'=>'县级代理分红',
	);
	$return['statuss']=array(
		'0'=>'订单待完成',
		'1'=>'待审核',
		'2'=>'待结算',
		'3'=>'已结算',
		'4'=>'审核不通过',
	);
	exi($return);
}
/*
	审核
*/
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		if(!$post['id']){
			exi('请先选择要审核的结算单！','error');
		}
		if(!$post['status']){
			exi('请先设置是否审核！','error');
		}
		$update=array(
			'status'=>intval($post['status']),
		);
		$this->update('commission',$update,array('id'=>intval($post['id'])));
		exi('审核成功！');
	}
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要审核的结算单！','error');
	}
	$item=$this->get('commission',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$item['nickname']=pdo_getcolumn('core_memebrs',array('id'=>$item['mid']),'nickname');
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'string','name'=>'ordersn','title'=>'挪车卡订单号'),
			array('type'=>'price','name'=>'fee','title'=>'金额'),
			array('type'=>'string','name'=>'nickname','title'=>'所属代理商'),
			array('type'=>'radio','name'=>'status','title'=>'是否审核','options'=>'statuss'),
		),
	);
	$return['statuss']=array(
		'2'=>'审核通过',
		'4'=>'审核不通过',
	);
	exi($return);
}